/**注册第三步*/

function GetRequest() {
    var url = unescape(location.search);
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

$(function(){
	var sweetcookie = new sweetCookie();
    var donkeyNum =  sweetcookie.getCookie("donkeyNum");
    var name =  sweetcookie.getCookie("name");
    var companyName =  sweetcookie.getCookie("companyName");
	$("#donkeyNum").val(donkeyNum);
	$("#name").val(name);
	$("#companyName").val(companyName);
	
	if(donkeyNum==null){
		location.href="/Lvscore_Advertiser_Maven/advertiserWeb/views/login/E-mail.html";
	}
	
	//固定电话
	$("#phonePat").hide();
	$("input[name='fixedPhone']").on("blur",function(){
		var result=pattern();
		if(result){
			$("#phonePat").hide();
		}else{
			$("#phonePat").show();
			$(".oldphone").hide();
		}
	})
	//qq
	$("#qqPat").hide();
	$("input[name='qq']").on("blur",function(){
		var result=qqpattern();
		if(result){
			$("#qqPat").hide();
		}else{
			$("#qqPat").show();
			$(".oldqq").hide();
		}
	})
	//手机号
	$("#mobilePat").hide();
	$("input[name='mobilePhone']").on("blur",function(){
		var result=mobilepattern();
		if(result){
			$("#mobilePat").hide();
		}else{
			$("#mobilePat").show();
			$(".oldmobile").hide();
		}
	})
	//邮箱
	$("#emailPat").hide();
	$("input[name='adminMail']").on("blur",function(){
		var result=emailpattern();
		if(result){
			$("#emailPat").hide();
		}else{
			$("#emailPat").show();
		}
	})
	//银行卡号
	$("#accountPat").hide();
	$("input[name='accountNumber']").on("blur",function(){
		var result=accountpattern();
		if(result){
			$("#accountPat").hide();
		}else{
			$("#accountPat").show();
			$(".oldaccount").hide();
		}
	});
	//确认提交
	$("body").on("mousemove",function(){ //全为必填时的验证
		if(pattern() && qqpattern() && mobilepattern() && accountpattern() && emailpattern()){
			$(".step1SubmitBtn").attr("disabled",false);
			$(".step1SubmitBtn").on("click",function(){
				doregister3();
			})
		}else{
			$(".step1SubmitBtn").attr("disabled",true);
		}
	});
})

//正则验证
	function pattern(){ //固定电话
		var phoneVal=$("input[name='fixedPhone']").val();
		var patFixedPhone=/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;     
		if(patFixedPhone.test(phoneVal)||!phoneVal){
			return true;
		}else{
			return false;
		};
	};
	function qqpattern(){ //qq
		var qqVal=$("input[name='qq']").val();
		var patQQ=/^\d{5,12}$/;     
		if(patQQ.test(qqVal)||!qqVal){
			return true;
		}else{
			return false;
		}
	};
	function mobilepattern(){ //手机号
		var mobileVal=$("input[name='mobilePhone']").val();
		var patMobile=/^[1][3578][0-9]{9}$/;     
		if(patMobile.test(mobileVal)||!mobileVal){
			return true;
		}else{
			return false;
		}
	};
	function emailpattern(){ //邮箱
		var emailVal=$("input[name='adminMail']").val();
		var patEmail=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;     
		if(patEmail.test(emailVal)||!emailVal){
			return true;
		}else{
			return false;
		}
	};
	function accountpattern(){ //银行卡号
		var accountVal=$("input[name='accountNumber']").val();
		var patAccount=/^(\d{16}|\d{19})$/;     
		if(patAccount.test(accountVal)||!accountVal){
			return true;
		}else{
			return false;
		}
	};

	
	
//点击 函数
	function doregister3() {
		$.ajax({
			url : "/Lvscore_Advertiser_Maven/registerPageThree",
			type : "post",
			dataType : "json",
			data : $("#adform3").serialize(),
			success : function(data) {
				var registerReturnBean = data.registerReturnBean;
				
				location.href="/Lvscore_Advertiser_Maven/advertiserWeb/views/login/registerStep4.html";
			}
		});
	}
